package com.small.nine.wxmp.domain.bean.wx.kf.msg;

import com.small.nine.wxmp.common.constant.WxConstant;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客服返回 图文信息
 *
 * @author sheng_zs@126.com
 * @date 2021-08-06 17:06
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class WxKfNewsMsgBean extends WxKfMsgBaseBean {
    private static final long serialVersionUID = 1L;

    /**
     * 消息内容
     */
    private Map<String, Object> news;

    /**
     * 初始化，并返回
     *
     * @param toUser      发送对象
     * @param url         点击图文信息跳转的 url
     * @param picUrl      图片链接
     * @param title       标题
     * @param description 说明
     * @return {@link WxKfNewsMsgBean}
     */
    public static WxKfNewsMsgBean getInstance(String toUser, String url, String picUrl, String title, String description) {
        WxKfNewsMsgBean msgBean = new WxKfNewsMsgBean();
        msgBean.setToUser(toUser);
        msgBean.setMsgType(WxConstant.MSG_TYPE_NEWS);
        // 图文信息
        HashMap<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> articlesMap = new HashMap<>();
        articlesMap.put(WxConstant.PARAM_TITLE, title);
        articlesMap.put(WxConstant.PARAM_DESCRIPTION, description);
        articlesMap.put(WxConstant.PARAM_PIC_URL, picUrl);
        articlesMap.put(WxConstant.PARAM_URL, url);
        // 只能添加一个
        list.add(articlesMap);
        map.put(WxConstant.PARAM_ARTICLES, list);
        msgBean.setNews(map);
        return msgBean;
    }
}
